public class test {
    class Solution {
        public int lengthOfLongestSubstring(String s) {
            //滑动窗口
            int left = 0,right = 0;
            int maxLength = 0;
            HashSet<Character> hashset = new HashSet<>();
            while(left<=right && right<s.length()){
                if(!hashset.contains(s.charAt(right))){
                    hashset.add(s.charAt(right));
                    maxLength = Math.max(maxLength,right-left+1);
                    right++;
                }else{
                    hashset.remove(s.charAt(left));
                    left++;
                }
            }
            return maxLength;
        }
    }
}
